<?php
namespace Kxdr\Model;
use Think\Model\ViewModel;
class EventPlayerViewModel extends ViewModel {
	public $sid;
	public $eid;
	public $uid;
   public $viewFields = array(
	 'e_player'=>array('_table'=>'sm_kxdr_event_players','id'=>'epid','title','think_type','think_type_way','think_type_sign','target_data','event_id','player_id','player_descrip'=>'event_player_descrip','_type'=>'LEFT'),
	 'player'=>array('_table'=>'sm_kxdr_players','id','chinese_name'=>'player_name','description'=>'player_descrip','is_team','team_id','_on'=>'e_player.player_id=player.id','game_category','_type'=>'LEFT'),
     );
   public function getEventPlayerView(){
		$players = $this->where("`e_player`.`event_id`=".$this->eid." AND `e_player`.`sid`=".$this->sid)->getField("epid,player_id,event_player_descrip,title,think_type,think_type_way,player_name,player_descrip,is_team");
		$GUE = D("UserGuess");
		$guess = $GUE->where("`sid`=".$this->sid." AND `eid`=".$this->eid." AND `user_id`=".$this->uid)->getField("`id`,`epid`,`guess_value`,`guess_type`,`player_id`,`guess_time`");
		foreach($players as $k=>$p){
			foreach(C("KXDR_THINK_WAY") as $way){
				if($p["think_type_way"]==$way["id"]){
					$players[$k]["think_type_way_name"]=$way["name"];break;
				}
			}
			foreach($guess as $gu){
				if($p["epid"]==$gu["epid"]){
					$players[$k]["guess"]=$gu;
				}
			}
		}
		return $players;
   }
}